home *** CD-ROM | disk | FTP | other *** search
- Path: news.walrus.com!news
- From: fjordao@walrus.com (Felipe Jordao)
- Newsgroups: comp.lang.c++
- Subject: [Q] equivalent or better strtok() in C++?
- Date: Thu, 25 Jan 1996 02:13:07 GMT
- Organization: HAC
- Message-ID: <4e6p1m$anc@walrus2.walrus.com>
- NNTP-Posting-Host: p22.ts1.walrus.com
- X-Newsreader: Forte Free Agent 1.0.82
-
- Hi,
-
- I have been trying to use strtok() to get tokens from a delimited
- string but it only recognizes tokens with one or more characters. (I
- know this is how the function is defined).
-
- However...
-
- if I have a string like this:
-
- "one.two.three..five."
-
- then using
- foo[0] = strtok(somebuffer, ".");
- foo[1] = strtok(NULL, "."); /// subsequent strtoks would be in a loop
- foo[2] = strtok(NULL, ".");
- .
- .
- foo[4] = strtok(NULL, ".");
-
- will give me ... as opposed to
-
- foo[0] = one foo[0] = one
- foo[1] = two foo[1] = two
- foo[2] = three foo[2] = three
- foo[3] = five foo[3] = <something> or maybe even NULL
- foo[4] = NULL foo[4] = five
-
-
- I would like to get the results on the right by using either strtok()
- or some other better iostream function (if there is any). I know I
- can resort to reading the line character by character, but that's too
- inefficient when the line is very long.
-
- any suggestions?
- thanks
- Felipe
-
-